package demo2;

public class Person {
    public static void main(String[] args) {
        Person person = new Person();
        System.out.println(person);

        person.setAge(18);
        System.out.println(person);


        person.setAge(-10);
        System.out.println(person);
    }
    private int age;

    public void setAge(int age) {
        if (age >=0 && age <=150){
            this.age = age;
            System.out.println("年龄设置成功");
        }else{
            System.out.println("年龄不合法");
        }

    }
}
